## 窗口层，模仿layui的layer来设计
## https://layui.dev/docs/2/layer
class_name WindowLayer

#region create window
static func open(options: WindowLayerOption) -> Window:
	return null
	
static func alert(content: String, options: WindowLayerOption = null, yes: Callable = Callable()) -> Window:
	return null
	
static func confirm(content: String, options: WindowLayerOption = null, yes: Callable = Callable(), cancel: Callable = Callable()) -> Window:
	return null

static func msg(content: String, options: WindowLayerOption = null, end: Callable = Callable()) -> Window:
	return null
	
static func load(icon: WindowLayerOption.WindowIcon, options: WindowLayerOption = null) -> Window:
	return null
	
static func tips(content: String, elem: Node2D, options: WindowLayerOption = null) -> Window:
	return null
	
static func prompt(options: WindowLayerOption = null, yes: Callable = Callable(), 
	formType: WindowLayerOption.PromptType = WindowLayerOption.PromptType.LineEdit, 
	value: String = "", maxLength: int = 500, placeholder: String = "") -> Window:
	return null
#endregion create window

#region common
static func calc_position(window: Window, offset: WindowLayerOption.WindowOffset = WindowLayerOption.WindowOffset.position) -> Vector2i:
	if offset == WindowLayerOption.WindowOffset.position:
		return window.position if window else Vector2i.ZERO
	elif offset == WindowLayerOption.WindowOffset.lt:
		return Vector2i(0, 0)
	var window_size: Vector2i = get_size(window)
	var container_size: Vector2i = get_container_size(window)
	if offset == WindowLayerOption.WindowOffset.auto:
		return Vector2i((container_size.x-window_size.x)/2, (container_size.y-window_size.y)/2)
	elif offset == WindowLayerOption.WindowOffset.t:
		return Vector2i((container_size.x-window_size.x)/2, 0)
	elif offset == WindowLayerOption.WindowOffset.r:
		return Vector2i(container_size.x-window_size.x, (container_size.y-window_size.y)/2)
	elif offset == WindowLayerOption.WindowOffset.b:
		return Vector2i((container_size.x-window_size.x)/2, container_size.y-window_size.y)
	elif offset == WindowLayerOption.WindowOffset.l:
		return Vector2i(0, (container_size.y-window_size.y)/2)
	elif offset == WindowLayerOption.WindowOffset.rt:
		return Vector2i(container_size.x-window_size.x, 0)
	elif offset == WindowLayerOption.WindowOffset.rb:
		return Vector2i(container_size.x-window_size.x, container_size.y-window_size.y)
	elif offset == WindowLayerOption.WindowOffset.lb:
		return Vector2i(0, container_size.y-window_size.y)
	else:
		return Vector2i.ZERO
	
static func get_size(node: Node) -> Vector2i:
	if node == null or not is_instance_valid(node):
		return Vector2i.ZERO
	var properties: Array[Dictionary] = node.get_property_list()
	if properties.size() == 0:
		return Vector2i.ZERO
	for item: Dictionary in properties:
		if item["name"] == "size" and item["type"] == TYPE_VECTOR2I:
			return node.get("size")
	return Vector2i.ZERO
	
static func get_container_size(node: Node) -> Vector2i:
	if node == null or not is_instance_valid(node):
		return Vector2i.ZERO
	var size: Vector2i = get_size(node.get_parent())
	if size != Vector2i.ZERO:
		return size
	size = get_size(node.owner)
	if size != Vector2i.ZERO:
		return size
	var window: Window = node.get_window()
	if window != null and is_instance_valid(window):
		return window.size
	return node.get_viewport().get_visible_rect().size
#endregion common
